import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 消息级别枚举 */
export enum MessageLevelEnum {
  /** 跟踪消息，一般用于普通输出 */
  Trace = 1,
  /** 信息消息 */
  Info = 2,
  /** 成功消息 */
  Success = 3,
  /** 警告消息 */
  Warn = 4,
  /** 错误消息 */
  Error = 5,
  /** 异常消息 */
  Fatal = 6,
}

/** 消息级别实体 */
export class MessageLevelEntity {
  /** 消息级别 */
  MessageLevel: MessageLevelEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(messageLevel: MessageLevelEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.MessageLevel = messageLevel;
    this.Color = color;
    switch (messageLevel) {
      case MessageLevelEnum.Trace:
        // this.Display = '跟踪消息';
        this.Display = t('enum.messageLevel.trace');
        this.Color = this.Color ? this.Color : PresetColorEnum.Default;
        break;
      case MessageLevelEnum.Info:
        // this.Display = '信息消息';
        this.Display = t('enum.messageLevel.info');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case MessageLevelEnum.Success:
        // this.Display = '成功消息';
        this.Display = t('enum.messageLevel.success');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case MessageLevelEnum.Warn:
        // this.Display = '警告消息';
        this.Display = t('enum.messageLevel.warn');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case MessageLevelEnum.Error:
        // this.Display = '错误消息';
        this.Display = t('enum.messageLevel.error');
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
      case MessageLevelEnum.Fatal:
        // this.Display = '异常消息';
        this.Display = t('enum.messageLevel.fatal');
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
    }
  }
}

//#region 获取消息级别枚举架构
/**
 * 获取消息级别枚举架构
 */
export function getMessageLevelEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: MessageLevelEntity[] = [
    new MessageLevelEntity(MessageLevelEnum.Trace),
    new MessageLevelEntity(MessageLevelEnum.Info),
    new MessageLevelEntity(MessageLevelEnum.Success),
    new MessageLevelEntity(MessageLevelEnum.Warn),
    new MessageLevelEntity(MessageLevelEnum.Error),
    new MessageLevelEntity(MessageLevelEnum.Fatal),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.MessageLevel as number,
      label: item.Display,
      value: item.MessageLevel as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
